@extends('layouts.back_stage')
@section('content')
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/commonjs/jquery.page.js?v=1.0.3"></script>
    <style>
        .seek_p{width:100%;margin:0 auto;padding-top:10px;}
        .seek_lab{width:185px;line-height:30px;margin-right:10px;}
        .seek_sel{width:130px;height: 30px;line-height:30px;float:right;outline:none;font-size: 13px;padding:5px 10px;font-weight: normal;border-radius: 2px;color: #555;background:#fff;background-image: none;border: 1px solid #cfdadd;box-shadow: none;}
        .bt_del{text-align: center;display:inline-block;}
        .fabric-choose{width:100%;line-height:30px;height:30px;margin:20px auto;}
        .fabric_div1{width:200%;}
        .fabric_div2{width:100%;}
        .fabric_div2{margin-top:30px;}
        .tab1,.tab2{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;margin-bottom:10px;}
        table td{text-align:center;height:35px;}
        table,th,td{border:1px solid #ccc;}
        .oneTb,.twoTb{width:100%;overflow-x:scroll;overflow-y:hidden;}
        .one_tr{cursor:pointer;}
        .one_tr.in{background:#27c24c;color:#fff;}
        ::-webkit-scrollbar{width:5px;height:5px;}
        .colr{color:red;}
        .colb{color:#1aad1a;}
    </style>
    <script>
        //供应商
        var suppliers = [
            <?php $j = count($suppliers_arr);$i = 0; ?>
                    @foreach ($suppliers_arr as $k=>$v )'{{$v["name"]}}'<?php $i++;?> @if($i<$j),@endif
            @endforeach
        ];
    </script>
    <div class="container">
        {{--面辅料采购入库--}}
        <div style="padding:20px 0;"><h3>面辅料采购入库</h3></div>
        <div class="form-group">
            <form>
                <p class="seek_p">
                    <label class="seek_lab" style="width:205px;">销售季节：
                        <select class="seek_sel sale_quarter" name="sale_quarter">
                            <option value="">请选择</option>
                            @if(count($season))
                                @foreach($season as $k => $v)
                                    <option value="{{$v}}">{{$v}}</option>
                                @endforeach
                            @endif
                        </select>
                    </label>
                    <label class="seek_lab" style="width:190px;">供应商：
                        <select class="seek_sel supplier_id">
                            <option value="">请选择</option>
                            @if(count($suppliers_arr))
                                @foreach($suppliers_arr as $k => $v)
                                    <option value="{{$v['supplier_id']}}">{{$v['name']}}</option>
                                @endforeach
                            @endif
                        </select>
                    </label>
                    <label class="seek_lab">款号：<input class="seek_sel girard" type="text" autocomplete="off" autocorrect="off" placeholder="款号" name="girard" value="" /></label>
                    <button type="button" class="btn bt_del btn-info" onclick="grabble()">搜索</button>
                    <a class="btn bt_del btn-info" href="javascript:;" onclick="emptyFabric()">清空</a>
                </p>
            </form>
        </div>
        <div class="fabric-choose">
            <span>共<span class="mate_count">0</span>条信息</span>
            <a class="btn btn-danger bt_a" href="javascript:;" onclick="Jversa()">反审</a>
            <a class="btn btn-info bt_a" href="javascript:;" onclick="Jaudit()">审核</a>
            <a class="btn btn-info bt_a" href="javascript:;" onclick="Edits()">修改</a>
            <a class="btn btn-info bt_a" href="javascript:;" onclick="Jadd()">添加</a>
        </div>
        <div class="form-group oneTb">
            <div class="fabric_div1">
                <table class="tab1">
                    <thead>
                        <tr>
                            <td>单据类型</td>
                            <td>单据号</td>
                            <td>供应商加工厂</td>
                            <td>入库仓库</td>
                            <td>摆放位置</td>
                            <td>采购数量</td>
                            <td>入库数量</td>
                            <td>金额</td>
                            <td>销售季节</td>
                            <td>服务款号</td>
                            <td>审核状态</td>
                            <td>仓库审核人</td>
                            <td>仓库审核时间</td>
                            <td>制单人</td>
                            <td>制单日期</td>
                            <td>对应计划单号</td>
                            <td>来源单号</td>
                            <td>收发类型</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
        <span class="page1" style="float:right;"></span>
        <div style="width:100%;border-top:1px solid #ccc;float:right;height:1px;margin-top:15px;"></div>
        <div class="form-group twoTb">
            <div class="fabric_div2">

            </div>
        </div>
    </div>
    <script>
        /*刚进页面初始化*/
        $.ajax({
            url:'/purchase/purchase-storage-list',
            type:'post',
            data:{skip:1},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            dataType:'json',
            success:function(data){
                $(".tab1 tbody").empty();
                $(".fabric_div2").empty();
                if(data.success){
                    var sts1='';
                    var res=data.info.content;
                    if(res.length>0){
                        for(var f in res){
                            if(res[f].status=='未审核'){
                                var sts0='<td class="stats">'+res[f].status+'</td>';
                            }else if(res[f].status=='已审核'){
                                var sts0='<td class="stats colb">'+res[f].status+'</td>';
                            }
                            sts1=sts1+'<tr class="one_tr" abc='+res[f].id+'>' +
                                '<td>'+res[f].purchase_type+'</td>' +
                                '<td>'+res[f].storage_num+'</td>' +
                                '<td>'+res[f].supplier_name+'</td>' +
                                '<td>'+res[f].warehouse+'</td>' +
                                '<td>'+res[f].position+'</td>' +
                                '<td>'+res[f].purchase_need+'</td>'+
                                '<td>'+res[f].warehouse_need+'</td>'+
                                '<td>'+res[f].price+'</td>' +
                                '<td>'+res[f].sale_quarter+'</td>' +
                                '<td>'+res[f].server_girards+'</td>' +
                                ''+sts0+'' +
                                '<td class="check_person">'+res[f].warehouse_person+'</td>'+
                                '<td class="check_time">'+res[f].warehouse_time+'</td>' +
                                '<td>'+res[f].make_order_person+'</td>' +
                                '<td>'+res[f].make_order_time+'</td>'+
                                '<td>'+res[f].plan_num+'</td>' +
                                '<td>'+res[f].notice_num+'</td>' +
                                '<td>'+res[f].other_type+'</td>' +
                                '<td>'+res[f].remark+'</td>' +
                                '</tr>';
                        }
                        $(".mate_count").text(data.info.page_count);
                        $(".tab1 tbody").append(sts1);
                        dec(data.info.page_count,'page1');
                    }else{
                        $(".mate_count").text("0");
                        $(".tab1 tbody").append('<tr><td colspan="19">无数据</td></tr>');
                    }
                }else{
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text(data.msg);
                    $(".oSuccess").show(0).delay(1000).hide(0);
                }
            }
        });
        /*一级点击*/
        var flag=true;
        $(document).on("click",".one_tr",function(){
            $(".fabric_div2").empty();
            var id=$(this).attr("abc");
            $(this).addClass("in").siblings().removeClass("in");
            if(flag) {
                $.ajax({
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                    url: '/purchase/pst-list-details',
                    type: 'post',
                    data: {id: id},
                    dataType: 'json',
                    beforeSend: function () {//触发ajax请求开始时执行
                        flag = false;
                    },
                    success: function (data) {
                        if(data.success){
                            var sts3='';
                            var res=data.info.content;
                            var cos=data.info.total;
                            if(res.length>0){
                                for(var f in res){
                                    sts3=sts3+'<tr class="two_tr">' +
                                        '<td>'+res[f].type+'</td>' +
                                        '<td>'+res[f].fabric_name+'</td>' +
                                        '<td>'+res[f].fabric_num+'</td>' +
                                        '<td>'+res[f].fabric_color+'</td>' +
                                        '<td>'+res[f].colors_remark+'</td>' +
                                        '<td>'+res[f].specification+'</td>' +
                                        '<td>'+res[f].purchase_need+'</td>' +
                                        '<td>'+res[f].warehouse_need+'</td>' +
                                        '<td>'+res[f].cost+'</td>' +
                                        '<td>'+res[f].price_sum+'</td>' +
                                        '<td>'+res[f].unit+'</td>' +
                                        '</tr>';
                                }
                                var sts4='<thead><tr><td>类型</td><td>小类</td><td>厂家货号</td><td>面辅料颜色</td><td>颜色说明</td><td>面辅料规格</td><td>采购数量(<span class="colr">合计:'+cos.purchase_need_sum+'</span>)</td><td>入库数量(<span class="colr">合计:'+cos.warehouse_need_sum+'</span>)</td><td>单价</td><td>金额(<span class="colr">合计:'+cos.price_sum+'</span>)</td><td>单位</td></tr></thead>';
                                $(".fabric_div2").append('<table class="tab2">'+sts4+'<tbody>'+sts3+'</tbody></table>');
                            }else{
                                var sts4='<thead><tr><td>类型</td><td>小类</td><td>厂家货号</td><td>面辅料颜色</td><td>颜色说明</td><td>面辅料规格</td><td>采购数量</td><td>入库数量</td><td>单价</td><td>金额</td><td>单位</td></tr></thead>';
                                $(".fabric_div2").append('<table class="tab2">'+sts4+'<tbody><tr><td colspan="16">无数据</td></tr></tbody></table>');
                            }
                        }else{
                            $(".faceImg").attr("src","/img/weep.png");
                            $(".oHandle").text(data.msg);
                            $(".oSuccess").show(0).delay(1000).hide(0);
                        }
                    },
                    complete: function () {//ajax请求完成时执行
                        flag = true;
                    }
                });
            }
        });
        /*清空*/
        function emptyFabric(){
            $(".seek_sel").each(function(){
                $(this).val("");
            })
        }
        /*搜索*/
        function grabble(){
            var sale_quarter=$(".sale_quarter").val();
            var supplier_id=$(".supplier_id").val();
            var girard=$(".girard").val();
            $.ajax({
                url:'/purchase/purchase-storage-list',
                type:'post',
                data:{
                    skip:1,
                    sale_quarter:sale_quarter,
                    supplier_id:supplier_id,
                    girard:girard
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".tab1 tbody").empty();
                    $(".fabric_div2").empty();
                    if(data.success){
                        var sts1='';
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                if(res[f].status=='未审核'){
                                    var sts0='<td class="stats">'+res[f].status+'</td>';
                                }else if(res[f].status=='已审核'){
                                    var sts0='<td class="stats colb">'+res[f].status+'</td>';
                                }
                                sts1=sts1+'<tr class="one_tr" abc='+res[f].id+'>' +
                                    '<td>'+res[f].purchase_type+'</td>' +
                                    '<td>'+res[f].storage_num+'</td>' +
                                    '<td>'+res[f].supplier_name+'</td>' +
                                    '<td>'+res[f].warehouse+'</td>' +
                                    '<td>'+res[f].position+'</td>' +
                                    '<td>'+res[f].purchase_need+'</td>'+
                                    '<td>'+res[f].warehouse_need+'</td>'+
                                    '<td>'+res[f].price+'</td>' +
                                    '<td>'+res[f].sale_quarter+'</td>' +
                                    '<td>'+res[f].server_girards+'</td>' +
                                    ''+sts0+'' +
                                    '<td class="check_person">'+res[f].warehouse_person+'</td>'+
                                    '<td class="check_time">'+res[f].warehouse_time+'</td>' +
                                    '<td>'+res[f].make_order_person+'</td>' +
                                    '<td>'+res[f].make_order_time+'</td>'+
                                    '<td>'+res[f].plan_num+'</td>' +
                                    '<td>'+res[f].notice_num+'</td>' +
                                    '<td>'+res[f].other_type+'</td>' +
                                    '<td>'+res[f].remark+'</td>' +
                                    '</tr>';
                            }
                            $(".mate_count").text(data.info.page_count);
                            $(".tab1 tbody").append(sts1);
                            dec(data.info.page_count,'page1');
                        }else{
                            $(".mate_count").text("0");
                            $(".tab1 tbody").append('<tr><td colspan="19">无数据</td></tr>');
                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        };
        /*分页*/
        function dec(num,clas){
            $('.'+clas).createPage(function(n){
                //n即是页码，这里写你操作页面的东西
//                    console.log(n);
            },{
                pageCount:Math.ceil(Number(num)/10),//总页码,默认10
                current:1,//当前页码,默认1
                showPrev:true,//是否显示上一页按钮
                showNext:true,//是否显示下一页按钮
                showTurn:false,//是否显示跳转,默认可以
                showNear:2,//显示当前页码前多少页和后多少页，默认2
                pageSwap:true,//是否同意调剂,默认是。调剂会最大数量显示页码。例如当前页面之前无页码可以显示。则会增加之后的页码。
                showSumNum:false,//是否显示总页码
                align:'right'//对齐方式。默认右对齐。可选：left,right
            },{
                "color":"#ddd",//字体颜色
                "fontSize":14,//字体大小
                "pagesMargin":2,//每个页码或按钮之间的间隔
                "paddL":0,//左边留白
                "paddR":0,//右边留白
                "borderColor":"#ddd",//边线颜色
                "currentColor":"#ed601b",//当前页码的字体颜色
                "disableColor":"#bfbfbf",//不可点击按钮的字体颜色
                "disableBackColor":"#f2f2f2",//不可点击按钮的背景色
                "prevNextWidth":48,//上页下页的宽度
                "pagecountWidth":48,//共计多少也的宽度
                "trunWidth":110,//跳转模块宽度
                "pageWidth":(function(){})()//根据当前所有因素计算出来的最适合宽度。也可自己设定成固定值
            });
        };
        /*点击分页*/
        $(document).on("click",".tcdNumber",function () {
            var skip=$(this).text().trim();
            var sale_quarter=$(".sale_quarter").val();
            var supplier_id=$(".supplier_id").val();
            var girard=$(".girard").val();
            cliA(skip,sale_quarter,supplier_id,girard)
        });
        $(document).on("click",".prevPage",function () {
            var skip=$(".current").text().trim();
            var sale_quarter=$(".sale_quarter").val();
            var supplier_id=$(".supplier_id").val();
            var girard=$(".girard").val();
            cliA(skip,sale_quarter,supplier_id,girard)
        });
        $(document).on("click",".nextPage",function () {
            var skip=$(".current").text().trim();
            var sale_quarter=$(".sale_quarter").val();
            var supplier_id=$(".supplier_id").val();
            var girard=$(".girard").val();
            cliA(skip,sale_quarter,supplier_id,girard)
        });
        function cliA(skip,sale_quarter,supplier_id,girard){
            $.ajax({
                url:'/purchase/purchase-storage-list',
                type:'post',
                data:{
                    skip:skip,
                    sale_quarter:sale_quarter,
                    supplier_id:supplier_id,
                    girard:girard
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    $(".tab1 tbody").empty();
                    $(".fabric_div2").empty();
                    if(data.success){
                        var sts1='';
                        var res=data.info.content;
                        if(res.length>0){
                            for(var f in res){
                                if(res[f].status=='未审核'){
                                    var sts0='<td class="stats">'+res[f].status+'</td>';
                                }else if(res[f].status=='已审核'){
                                    var sts0='<td class="stats colb">'+res[f].status+'</td>';
                                }
                                sts1=sts1+'<tr class="one_tr" abc='+res[f].id+'>' +
                                    '<td>'+res[f].purchase_type+'</td>' +
                                    '<td>'+res[f].storage_num+'</td>' +
                                    '<td>'+res[f].supplier_name+'</td>' +
                                    '<td>'+res[f].warehouse+'</td>' +
                                    '<td>'+res[f].position+'</td>' +
                                    '<td>'+res[f].purchase_need+'</td>'+
                                    '<td>'+res[f].warehouse_need+'</td>'+
                                    '<td>'+res[f].price+'</td>' +
                                    '<td>'+res[f].sale_quarter+'</td>' +
                                    '<td>'+res[f].server_girards+'</td>' +
                                    ''+sts0+'' +
                                    '<td class="check_person">'+res[f].warehouse_person+'</td>'+
                                    '<td class="check_time">'+res[f].warehouse_time+'</td>' +
                                    '<td>'+res[f].make_order_person+'</td>' +
                                    '<td>'+res[f].make_order_time+'</td>'+
                                    '<td>'+res[f].plan_num+'</td>' +
                                    '<td>'+res[f].notice_num+'</td>' +
                                    '<td>'+res[f].other_type+'</td>' +
                                    '<td>'+res[f].remark+'</td>' +
                                    '</tr>';
                            }
                            $(".mate_count").text(data.info.page_count);
                            $(".tab1 tbody").append(sts1);
                        }else{
                            $(".mate_count").text("0");
                            $(".tab1 tbody").append('<tr><td colspan="19">无数据</td></tr>');
                        }
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            });
        }
        /*审核*/
        function Jaudit(){
            var id=$(".one_tr.in").attr("abc");
            if(id==undefined){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("先选择一条信息再审核");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if($(".one_tr.in").children(".stats").text()=="已审核"){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("该信息已审核，不能重复操作");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".oText").text("确定要审核吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','audits');
        }
        /*点确定*/
        $(document).on('click','#audits',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url:'/purchase/storage-review',
                type:'post',
                data:{id:id,status:1},
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        console.log(data);
                        $(".one_tr.in").children(".stats").text("已审核");
                        $(".one_tr.in").children(".stats").addClass("colb");
                        $(".one_tr.in").children(".check_person").text(data.info.person);
                        $(".one_tr.in").children(".check_time").text(data.info.time);
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("审核成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
        /*反审*/
        function Jversa(){
            var id=$(".one_tr.in").attr("abc");
            if(id==undefined){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("先选择一条信息再反审");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if($(".one_tr.in").children(".stats").text()=="未审核"){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("该信息未审核，请先审核");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $(".oText").text("确定要反审吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','versas');
        }
        /*点确定*/
        $(document).on('click','#versas',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url:'/purchase/storage-review',
                type:'post',
                data:{id:id,status:-1},
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        $(".one_tr.in").children(".stats").text("未审核");
                        $(".one_tr.in").children(".stats").removeClass("colb");
                        $(".one_tr.in").children(".check_person").text("");
                        $(".one_tr.in").children(".check_time").text("");
                        $(".faceImg").attr("src","/img/laugh.png");
                        $(".oHandle").text("反审成功");
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        });
        /*添加*/
        function Jadd() {
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url:'/purchase/get-storage-id',
                type:'post',
                data:{},
                dataType:'json',
                success:function (data) {
                    if(data.success){
                        window.location.href='/purchase/purchase-storage-update?id='+data.info;
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(data.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }
                }
            })
        }
        /*修改*/
        function Edits() {
            var id=$(".one_tr.in").attr("abc");
            if(id==undefined){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("先选择一条信息再修改");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            if($(".one_tr.in").children(".stats").text().trim()=="已审核"){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("该信息已审核，不能修改");
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            window.location.href='/purchase/purchase-storage-update?id='+id;
        }
    </script>
@endsection
